﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iLangl.Model.Rules
{
	public class ValidateStateHistory : IValidation
	{
		StateHistory history;
		#region IValidation Members

		public IList<IError> Validate(object item)
		{
			List<IError> result = new List<IError>();

			if (!(item is StateHistory))
			{
				result.Add(new Error(
					"Validation Failed",
					String.Format("Expected type ='StateHistory' instead of {0}", item.GetType()),
					eSeverity.High));

				return result;
			}

			history = item as StateHistory;


			if (history.ChangedDate.Ticks >= DateTime.Now.Ticks)
			{
				result.Add(new Error(
				"Change History Date can't be in future!",
				string.Format("History.Change Date is specified in future and this is wrong.{0}!",
				(history.Owner == null) ?
					string.Empty :
					history.Owner.ToString()),
				eSeverity.Medium));
			}

			if (history.ChangedPerson == null)
			{
				result.Add(new Error(
				"Change History Person is not specified!",
				string.Format("History.Change Person is not specified.{0}!",
				(history.Owner == null) ?
					string.Empty :
					history.Owner.ToString()),
				eSeverity.Medium));
			}

			if (String.IsNullOrEmpty(history.State))
			{
				result.Add(new Error(
				"State History is not specified!",
				string.Format("History.State is not specified.{0}!",
				(history.Owner == null) ?
					string.Empty :
					history.Owner.ToString()),
				eSeverity.Medium));
			}

			return result;
		}

		#endregion
	}
}
